package fr.iut2.sil4.data;

import java.util.Calendar;

public class Week {
	
	private Calendar start, end;
	
	public Week() {
	}
	
	public static Week getCurrentWeek() {
		Week currentWeek = new Week();
		Calendar today = Calendar.getInstance();
		Calendar start = Calendar.getInstance();
		Calendar end = Calendar.getInstance();
		
		if (today.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
			start.set(Calendar.DAY_OF_MONTH, (today.get(Calendar.DAY_OF_MONTH)-(today.get(Calendar.DAY_OF_WEEK)-Calendar.MONDAY)));
		}
		start.set(Calendar.HOUR_OF_DAY, 8);
		start.set(Calendar.MINUTE, 0);
		start.set(Calendar.SECOND, 0);
		start.set(Calendar.MILLISECOND, 0);
		
		currentWeek.setStart(start);
		
		end.set(Calendar.DAY_OF_MONTH, start.get(Calendar.DAY_OF_MONTH)+(Calendar.FRIDAY-Calendar.MONDAY+1));
		end.set(Calendar.HOUR_OF_DAY, 18);
		end.set(Calendar.MINUTE, 0);
		end.set(Calendar.SECOND, 0);
		end.set(Calendar.MILLISECOND, 0);
		
		currentWeek.setEnd(end);
		 return currentWeek;
	}
	
	public Week previous() {
		Week previousWeek = new Week();
		Calendar start = (Calendar)getStart().clone();
		start.set(Calendar.DAY_OF_MONTH, (start.get(Calendar.DAY_OF_MONTH)-7));
		previousWeek.setStart(start);
		
		Calendar end = (Calendar)getEnd().clone();
		end.set(Calendar.DAY_OF_MONTH, (end.get(Calendar.DAY_OF_MONTH)-7));
		previousWeek.setEnd(end);
		
		return previousWeek;
	}
	
	public Week next() {
		Week nextWeek = new Week();
		Calendar start = (Calendar)getStart().clone();
		start.set(Calendar.DAY_OF_MONTH, (start.get(Calendar.DAY_OF_MONTH)+7));
		nextWeek.setStart(start);
		
		Calendar end = (Calendar)getEnd().clone();
		end.set(Calendar.DAY_OF_MONTH, (end.get(Calendar.DAY_OF_MONTH)+7));
		nextWeek.setEnd(end);
		
		return nextWeek;
	}
	
	public Calendar getStart() {
		return start;
	}

	public void setStart(Calendar start) {
		this.start = start;
	}

	public Calendar getEnd() {
		return end;
	}

	public void setEnd(Calendar end) {
		this.end = end;
	}
}
